<template>
    <div>
        <h1>优惠券增加</h1>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <th align="right">券类型</th>
                    <th>
                        <select v-model="queryinfo.DType">
                            <option value="">请选择</option>
                            <option value="代金券">代金券</option>
                            <option value="折扣券">折扣券</option>
                            <option value="兑换券">兑换券</option>
                        </select>
                    </th>
                </tr>
                <tr>
                    <th align="right">优惠券标题</th>
                    <th>
                        <input type="text" v-model="queryinfo.DTitle">
                    </th>
                </tr>
                <tr>
                    <th align="right">优惠券图片</th>
                    <th>
                        <input type="file" @change="imgs">
                        <img :src="queryinfo.Photo" width="100" height="100" v-if="queryinfo.Photo!=''">
                    </th>
                </tr>
                <tr>
                    <th align="right">剩余库存</th>
                    <th>
                        <input type="text" v-model="queryinfo.Number">
                    </th>
                </tr>
                <tr>
                    <th align="right">每人限额</th>
                    <th>
                        <input type="text" v-model="queryinfo.Limit">
                    </th>
                </tr>
                <tr>
                    <th align="right">使用条件</th>
                    <th>
                        <input type="text" v-model="queryinfo.PayMoney">
                    </th>
                </tr>
                <tr>
                    <th align="right">减免金额</th>
                    <th>
                        <input type="text" v-model="queryinfo.Money">
                    </th>
                </tr>
                <tr>
                    <th align="right">有效期</th>
                    <th>
                        <input type="date" v-model="queryinfo.BeginTime">
                        -<input type="date" v-model="queryinfo.EndTime"> 
                    </th>
                </tr>
                <tr>
                    <th align="right">使用业务</th>
                    <th>
                        <input type="checkbox" name="like" value="订房" v-model="queryinfo.Like">订房
                        <input type="checkbox" name="like" value="商城" v-model="queryinfo.Like">商城
                        <input type="checkbox" name="like" value="堂食" v-model="queryinfo.Like">堂食
                        <input type="checkbox" name="like" value="收款码" v-model="queryinfo.Like">收款码
                    </th>
                </tr>
                <tr>
                    <th align="right">使用须知</th>
                    <th>
                        <textarea v-model="queryinfo.Notice"></textarea>
                    </th>
                </tr>
                <tr>
                    <th align="right">适用门店</th>
                    <th>
                        <select v-model="queryinfo.Shop">
                            <option value="">请选择</option>
                            <option value="河北石家庄">河北石家庄</option>
                            <option value="广州白云山">广州白云山</option>
                            <option value="北京昌平区">北京昌平区</option>
                        </select>
                    </th>
                </tr>
                <tr>
                    <th align="right">服务电话</th>
                    <th>
                        <input type="text" v-model="queryinfo.Phone">
                    </th>
                </tr>
                <tr>
                    <th align="right"></th>
                    <th>
                        <input type="button" value="增加" class="btn btn-primary" @click="ok">
                    </th>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import { ref,reactive,onMounted } from 'vue';
import axios from 'axios';
import moment  from 'moment';
import { useRoute,useRouter } from 'vue-router';
const route=useRoute()
const router=useRouter()

let queryinfo:any=reactive({
  "DType": "",
  "DTitle": "",
  "Photo": "",
  "Number": "",
  "Limit": "",
  "PayMoney": "",
  "Money": "",
  "BeginTime": "",
  "EndTime": "",
  "Like": [],
  "Notice": "",
  "Shop": "",
  "Phone": "",
})

const imgs=(e:any)=>{
    let obj=e.target.files[0]
    let f=new FormData()
    f.append('file',obj)
    axios({
        url:'/api/Photo/Upload',
        method:'post',
        data:f
    })
    .then((res)=>{
        console.log(res);
        queryinfo.Photo=res.data
    })
}

const ok=()=>{

    queryinfo.Like=queryinfo.Like.toString()
    axios({
        url:'/api/Discount/AddDiscount',
        method:'post',
        data:queryinfo
    })
    .then((res)=>{
        if(res.data>0){
            alert("增加成功")

            return
        }
        else{
            alert("增加失败")
            return
        }
    })
}


</script>

<style scoped>

</style>